import type { PluginLifecycle, PluginContext } from '@bai-hu/plugin-sdk'

export const activate: PluginLifecycle['activate'] = async (ctx: PluginContext) => {
  ctx.logger.info('hello-world backend activated', ctx.manifest.name)

  // Demonstrate host http.fetch if allowed by permissions and config.fetchWhitelist
  try {
    const resp = await ctx.services.http?.fetch({ url: 'https://example.com', method: 'GET', timeoutMs: 2000 })
    ctx.logger.info('fetched example.com', { status: resp?.status })
  } catch (e: any) {
    ctx.logger.warn('fetch failed', e?.message)
  }

  return () => ctx.logger.info('hello-world backend deactivated')
}

